

#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP

#include <QMainWindow>
#include <plot.hpp>
#include <QToolBar>
#include <QMap>
#include <QAction>

namespace Ui {
class MainWindow;
}

class CWave;
class QFFTWindow;
class QModHertzelWindow;
class TGenPanel;
class QTabWidget;
class QListWidget;
class QTextBrowser;
class TransformWindow;

struct NamedData;
struct NamedIntData;
class DataInterface;
class ReadFileFormatInterface;
class SaveFileFormatInterface;
class TransformNamedData;
class TransformNamedIntData;
class SaveLoadObjectInterface;

class MainWindow final : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
protected slots:
    void openWave();
    void recountFFT(int pos, int width);
    void setCurrent( int );
    void count_mod_gertzel();

    void loadTestData();

    void addLogMessage(QString);
    void startTransform();
    void onZoneChanged(double s, double e);

    void computationFinished();
private:
    void startDoubleCalculation();
    void startIntCalculation();
    void processTransformResult(QSharedPointer<NamedData>    result);
    void processTransformResult(QSharedPointer<NamedIntData> result);
protected:
    void ctrateToolBars();
    void addDock(QString , QWidget *, Qt::DockWidgetArea area = Qt::LeftDockWidgetArea);
    void loadPlugins();
    void populatePlugins(QObject *plugin);
    void addPanel(NamedData * dat);
protected:
    void closeEvent(QCloseEvent * event);
    void saveWndState();
    void loadWndState();
private:
    Ui::MainWindow *ui;
    QString last_opened_dir_;
    QString last_used_open_filter_;

    QFFTWindow * m_fft_wnd;
    QModHertzelWindow * m_Hertzel_wnd;
    TGenPanel * m_genPanel;
    TransformWindow* m_transform_wnd;
    TransformWindow* m_transform_pulse_wnd;

    QToolBar * m_mainToolBar;
    QAction  * m_openWaveAct;
    QAction  * m_addTestDataAct;
    QAction  * m_setZeroLenghtAct;
    QAction  * m_startTransformAct;

    QList<QSharedPointer<NamedData> > m_dataList;
    QList<QSharedPointer<NamedData> > m_transformDataList;
    QStringList m_openedFiles;

    //
    QTabWidget  * m_tabs;
    QListWidget * m_taskList;

    QTextBrowser * m_logBrowser;

    QStringList pluginFileNames_;
    QMap<QString, DataInterface*>           dataPlugins_;
    QMap<QString, ReadFileFormatInterface*> formatPlugins_;
    QMap<QString, SaveFileFormatInterface*> saveFormatPlugins_;
    QMap<QString, TransformNamedData*>      transformPlugins_;
    QMap<QString, TransformNamedIntData*>   transformIntPlugins_;
    QMap<QString, SaveLoadObjectInterface*> saveLoadObjectPlugins_;

private:

    double last_calc_base_time   =  0.;
    double last_calc_pulse_time_ =  0.;
    double last_calc_time_       =  0.;
    double delta_t_pulse_        = -1.;
    double delta_t_signal_       = -1.;
    double base_time             =  0.00534;// 0.000640644;
    double base_temp_            =  20.0;
};

#endif // MAINWINDOW_HPP

